package leetcode.code198;

public class Solution2 {

	public static void main(String[] args) {
		int[] nums = { 1, 3, 1 };
		int[] nums1 = { 2, 7, 9, 3, 1 };
		int[] nums2 = { 2, 1, 4, 5, 3, 1, 1, 3 };
		Solution2 solution = new Solution2();
		int result = solution.massage(nums2);
		System.out.println(result);
	}

	public int massage(int[] nums) {
		int len = nums.length;
		if (len == 0)
			return 0;
		if (len == 1)
			return nums[0];
		if (len == 2)
			return Math.max(nums[0], nums[1]);
		int[] result = new int[nums.length];
		result[0] = nums[0];
		result[1] = Math.max(nums[0], nums[1]);
		for (int i = 2; i < nums.length; i++) {
			result[i] = Math.max(result[i - 1], result[i - 2] + nums[i]);
		}
		return result[nums.length - 1];
	}

}
